package com.jyc.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jyc.entity.ck.Shebeiguihai;
import com.jyc.service.CKService;
import com.jyc.util.DateUtils;
import com.jyc.util.HttpResult;
import com.jyc.vo.ck.ShebeiguihaiVO;
import com.jyc.vo.zuche.ZucheChartVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@RestController
@CrossOrigin("*")
@RequestMapping("/ck")
public class CKController {
    @Autowired
    private CKService ckService;

    /**
     * 设备管理
     * @return
     */
    @RequestMapping("/toList")
    public HttpResult toList(@RequestParam("pageIndex") Integer pageIndex, @RequestParam("pageSize") Integer pageSize) {
        PageHelper.startPage(pageIndex,pageSize);

        List<Shebeiguihai> shebeiguihais = ckService.getItemList();
        List<ShebeiguihaiVO> shebeiguihaiVOS = new ArrayList<>();
        for (Shebeiguihai shebeiguihai : shebeiguihais) {
            ShebeiguihaiVO shebeiguihaiVO = new ShebeiguihaiVO();
            BeanUtils.copyProperties(shebeiguihai,shebeiguihaiVO);
            shebeiguihaiVO.setAddtime(DateUtils.convertDateToString(shebeiguihai.getAddtime()));
            shebeiguihaiVO.setGuihairiqi(DateUtils.convertDateToString(shebeiguihai.getGuihairiqi()));
            shebeiguihaiVOS.add(shebeiguihaiVO);
        }
        PageInfo<Shebeiguihai> pageInfo = new PageInfo<Shebeiguihai>(shebeiguihais, pageSize);
        return HttpResult.ok(pageInfo);
    }

    /**
     * 出租资产类型占比
     * @return
     */
    @RequestMapping("/showPie")
    public HttpResult showPie() {
        List<ShebeiguihaiVO> zucheChartVOS = ckService.showPie();
        return HttpResult.ok(zucheChartVOS);
    }

    /**
     * 不同资产的租用天数
     * @return
     */
    @RequestMapping("/showPillar")
    public HttpResult showPillar() {
        List<ShebeiguihaiVO> zucheChartVOS = ckService.showPillar();
        return HttpResult.ok(zucheChartVOS);
    }

    /**
     * 不同资产的租用数量
     * @return
     */
    @RequestMapping("/showLine")
    public HttpResult showLine() {
        List<ShebeiguihaiVO> zucheChartVOS = ckService.showLine();
        return HttpResult.ok(zucheChartVOS);
    }

    /**
     * x：日期，y：景点，z：购票信息
     * @return
     */
    @RequestMapping("/show3D")
    public HttpResult show3D() {
        Set<List> chartVOS = ckService.show3D();
        return HttpResult.ok(chartVOS);
    }
}
